﻿Imports System.Security.Principal

Module Module1
    Dim identity = WindowsIdentity.GetCurrent()
    Dim principal = New WindowsPrincipal(identity)
    Dim isElevated As Boolean = principal.IsInRole(WindowsBuiltInRole.Administrator)

    Dim WPIlib As New wpi_lib.repository.cli
    Sub Main()
        If Not isElevated Then
            PrintHelp()
            Exit Sub
        End If
        Dim A() As String = System.Environment.GetCommandLineArgs()
        Select Case A.Count
            Case Is = 2
                Select Case A(1).ToLower
                    Case Is = "update", "upd", "u"
                        WPIlib.UpdateRepos()

                    Case Is = "list", "lst", "l"
                        WPIlib.ListRepos()

                End Select

            Case Is = 3
                Select Case A(1).ToLower
                    Case Is = "add", "a"
                        WPIlib.AddRepo(A(2))

                    Case Is = "remove", "rm", "r"
                        WPIlib.RemoveRepo(A(2))

                End Select

            Case Else
                PrintHelp()

        End Select
    End Sub

    Private Sub PrintHelp()
        SetConsoleColors(ConsoleColor.green)
        Console.WriteLine("Windows Package Installer (WPI) - alpha")
        Console.WriteLine("")
        If Not isElevated Then
            SetConsoleColors(ConsoleColor.red)
            Console.WriteLine("WPI must be run in elevated mode!")
            Console.WriteLine("")
        End If
        SetConsoleColors(ConsoleColor.yellow)
        Console.WriteLine("Syntax")
        SetConsoleColors(ConsoleColor.white)
        Console.WriteLine("wpi-repo add url")
        Console.WriteLine("wpi-repo remove name")
        Console.WriteLine("wpi-repo update")
        Console.WriteLine("wpi-repo list")
        Console.WriteLine("")
        SetConsoleColors(ConsoleColor.grey)
    End Sub

End Module
